package com.jjtm.admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jjtm.admin.common.dto.MemberDto;
import com.jjtm.admin.service.MemberService;
import com.jjtm.common.core.po.Member;
import com.jjtm.common.core.utils.RedisUtils;
import com.jjtm.common.core.utils.ResultUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wangbaofeng
 * @since 2021-03-18
 */
@RestController
@RequestMapping("/member")
public class MemberController {

    @Resource
    MemberService memberService;

    @Resource
    RedisUtils redisUtils;

    @GetMapping("/addRedis")
    public Object addRedis(){
        redisUtils.set("nickName","你好啊",5, TimeUnit.SECONDS);
        return ResultUtil.success();
    }


    @GetMapping("/getRedis")
    public Object getRedis(){
        return ResultUtil.success(redisUtils.get("nickName"));
    }

    @GetMapping("/list")
    public Object list(MemberDto memberDto){
        QueryWrapper<Member> queryWrapper = new QueryWrapper<Member>();
        queryWrapper.lambda().like(Member::getNickName,memberDto.getNickName());
        return ResultUtil.success(memberService.page(new Page<>(memberDto.getPageIndex(),memberDto.getPageSize()),queryWrapper));
    }

}

